package com.ruoyi.cencat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cencat.domain.CencatRecordIn;
import com.ruoyi.cencat.service.ICencatRecordInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库记录Controller
 * 
 * @author cencat
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/cencat/in")
public class CencatRecordInController extends BaseController
{
    @Autowired
    private ICencatRecordInService cencatRecordInService;

    /**
     * 查询入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:list')")
    @GetMapping("/list")
    public TableDataInfo list(CencatRecordIn cencatRecordIn)
    {
        startPage();
        List<CencatRecordIn> list = cencatRecordInService.selectCencatRecordInList(cencatRecordIn);
        return getDataTable(list);
    }

    /**
     * 导出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:export')")
    @Log(title = "入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CencatRecordIn cencatRecordIn)
    {
        List<CencatRecordIn> list = cencatRecordInService.selectCencatRecordInList(cencatRecordIn);
        ExcelUtil<CencatRecordIn> util = new ExcelUtil<CencatRecordIn>(CencatRecordIn.class);
        util.exportExcel(response, list, "入库记录数据");
    }

    /**
     * 获取入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(cencatRecordInService.selectCencatRecordInByRecordId(recordId));
    }

    /**
     * 新增入库记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:add')")
    @Log(title = "入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CencatRecordIn cencatRecordIn)
    {
        return toAjax(cencatRecordInService.insertCencatRecordIn(cencatRecordIn));
    }

    /**
     * 修改入库记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:edit')")
    @Log(title = "入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CencatRecordIn cencatRecordIn)
    {
        return toAjax(cencatRecordInService.updateCencatRecordIn(cencatRecordIn));
    }

    /**
     * 删除入库记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:in:remove')")
    @Log(title = "入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(cencatRecordInService.deleteCencatRecordInByRecordIds(recordIds));
    }
}
